import { Controller, Context } from "egg";
import PlatformService from "../../service/platform";

/**
 * @Controller 流媒体平台管理 PlatformsController
 */
export default class PlatformController extends Controller implements RestfulController {
  private _service: PlatformService;

  constructor(ctx: Context) {
    super(ctx);
    this._service = ctx.service.platform;
  }

  /**
   * @summary 创建流媒体平台
   * @description 创建流媒体平台
   * @router POST /api/v1/pltforms
   * @request body PlatformOpReqModel
   * @response 200 PlatformOpResModel
   */
  async create() {
    const resp = await this._service.create(this.ctx.request.body);
    this.ctx.body = resp.body;
    this.ctx.status = resp.status;
  }

  /**
   * @summary 删除流媒体平台服务
   * @description 删除流媒体平台服务
   * @router DELETE /api/v1/platforms/{id}
   * @request path string *id 流媒体平台id
   * @response 200 BaseResModel
   */
  async destroy() {
    const { ctx } = this;
    const resp = await this._service.destroy(ctx.params.id);
    ctx.body = resp.body;
    ctx.status = resp.status;
  }

  /**
   * @summary 修改流媒体平台
   * @description 修改流媒体平台
   * @router PUT /api/v1/pltforms/{id}
   * @request path string *id 流媒体服务平台Id
   * @request body PlatformOpReqModel
   * @response 200 PlatformOpResModel
   */
  async update() {
    const resp = await this._service.update(this.ctx.params.id, this.ctx.request.body);
    this.ctx.body = resp.body;
    this.ctx.status = resp.status;
  }

  /**
   * @summary 查询流媒体平台列表
   * @description 查询流媒体平台列表
   * @router GET /api/v1/platforms
   * @request query string pltName 流媒体平台名称
   * @request query string pltState 流媒体平台状态
   * @response 200 BaseResModel
   */
  async index() {
    const { ctx } = this;
    const resp = await this._service.index(ctx.query);
    ctx.body = resp.body;
    ctx.status = resp.status;
  }

  /**
   * @summary 查询流媒体平台明细
   * @description 查询流媒体平台明细
   * @router GET /api/v1/platforms/{id}
   * @request path string *id 平台id
   * @response 200 BaseResModel
   */
  async show() {
    const resp = await this._service.show(this.ctx.params.id);
    this.ctx.body = resp.body;
    this.ctx.status = resp.status;
  }

  /**
   * @summary 分页查询流媒体平台
   * @description 分页查询流媒体平台
   * @router GET /api/v1/page/platforms
   * @request query integer *current 当前页
   * @request query integer *pageSize 每页条数
   * @request query string pltName 流媒体平台名称
   * @request query string pltState 流媒体平台状态
   * @response 200 BaseResModel
   */
  async page() {
    const resp = await this._service.page(this.ctx.query);
    this.ctx.body = resp.body;
    this.ctx.status = resp.status;
  }
}
